/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: VP Development
 * License Type: Purchased
 */
using System;
using Orm;
using System.Collections;
using NHibernate;

namespace petshop {
	/// <summary>
	/// ORM-Persistable Class
	/// </summary>
	public class Transaction {
		public Transaction() {
			_OrmAdapter = new TransactionORMAdapter(this);
			pets = new petshop.PetSetCollection(this, _OrmAdapter, petshop.ORMConstants.KEY_TRANSACTION_PETS, petshop.ORMConstants.KEY_MUL_ONE_TO_MANY);
		}
		
		public bool Save() {
			try {
				global::petshop.PetShopPersistentManager.Instance().SaveObject(this);
				return true;
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public bool Delete() {
			try {
				global::petshop.PetShopPersistentManager.Instance().DeleteObject(this);
				return true;
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public bool Refresh() {
			try {
				global::petshop.PetShopPersistentManager.Instance().GetSession().Refresh(this);
				return true;
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public bool DeleteAndDissociate() {
			try {
				if(Staff != null) {
					Staff.Transaction = null;
				}
				if(Customer != null) {
					Customer.Transaction = null;
				}
				return Delete();
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public bool DeleteAndDissociate(global::Orm.PersistentSession session) {
			try {
				if(Staff != null) {
					Staff.Transaction = null;
				}
				if(Customer != null) {
					Customer.Transaction = null;
				}
				try {
					session.Delete(this);
					return true;
				}
				catch (Exception) {
					return false;
				}
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		private Iesi.Collections.ISet This_GetSet(int key) {
			if (key == petshop.ORMConstants.KEY_TRANSACTION_PETS)
				return __pets;
			return null;
		}
		
		private class TransactionORMAdapter : Orm.Util.AbstractORMAdapter {
			private readonly Transaction __Transaction;
			
			internal TransactionORMAdapter(Transaction value) {
				__Transaction = value;
			}
			
			public override Iesi.Collections.ISet GetSet(int key) {
				return __Transaction.This_GetSet(key);
			}
			
		}
		
		internal Orm.Util.ORMAdapter _OrmAdapter;
		
		private DateTime? __date;
		
		private double __price;
		
		private int __ID;
		
		private global::petshop.Staff __staff;
		
		private global::petshop.Customer __customer;
		
		private Iesi.Collections.ISet __pets = new Iesi.Collections.HashedSet();
		
		public DateTime? Date {
			set {
				this.__date = value;				
			}
			get {
				return __date;				
			}
		}
		
		public double Price {
			set {
				this.__price = value;				
			}
			get {
				return __price;				
			}
		}
		
		private int ID {
			set {
				this.__ID = value;				
			}
			get {
				return __ID;				
			}
		}
		
		public int ORMID {
			get {
				return ID;				
			}
		}
		
		public global::petshop.Staff Staff {
			set {
				if (__staff != value) {
					if (this.__staff != null) {
						this.__staff.Transaction = null;
					}
					this.__staff = value;
					if (__staff != null) {
						__staff.Transaction = this;
					}
				}
			}
			get {
				return __staff;				
			}
		}
		
		public global::petshop.Customer Customer {
			set {
				if (__customer != value) {
					if (this.__customer != null) {
						this.__customer.Transaction = null;
					}
					this.__customer = value;
					if (__customer != null) {
						__customer.Transaction = this;
					}
				}
			}
			get {
				return __customer;				
			}
		}
		
		private Iesi.Collections.ISet ORM_Pets {
			get  {
				return __pets;				
			}
			
			set {
				__pets = value;				
			}
		}
		
		public readonly petshop.PetSetCollection pets;
		
		public override string ToString() {
			return Convert.ToString(ID);
		}
		
	}
}
